<?php
!function_exists('adminmsg') && exit('Forbidden');
InitGP(array('action'));
$reportService = House::loadService('houseReportService');
if (!$action) {
	InitGP(array('page', 'type'));
	(!is_numeric($page) || $page < 1) && $page=1;
	switch ($type) {
		case 'second':
			$reportdb = $reportService->get(0, 0, $page);
			$count = $reportService->count(0, 0);
			$totalCount = $count ? $count : 0;
			$numofpage = ceil($count/$db_perpage);
			$pageurl = $basename . '&type=second&';
			$pages=numofpage($count,$page,$numofpage,$pageurl);
			$select_second = 'selected';
			require_once PrintMode('report.run');
			break;
		case 'rent':
			$reportdb = $reportService->get(0, 1, $page);
			$count = $reportService->count(0, 1);
			$totalCount = $count ? $count : 0;
			$numofpage = ceil($count/$db_perpage);
			$pageurl = $basename . '&type=rent&';
			$pages=numofpage($count,$page,$numofpage,$pageurl);
			$select_rent = 'selected';
			require_once PrintMode('report.run');
			break;
		default:
			$reportdb = $reportService->getByHandle(0, $page);
			$count = $reportService->countByHandle(0);
			$totalCount = $count ? $count : 0;
			$numofpage = ceil($count/$db_perpage);
			$pageurl = $basename . '&';
			$pages=numofpage($count,$page,$numofpage,$pageurl);
			require_once PrintMode('report.run');
			break;
	}	
} elseif ($action == 'deal') {
	InitGP(array('page', 'type'));
	(!is_numeric($page) || $page < 1) && $page=1;
	switch ($type) {
		case 'second':
			$reportdb = $reportService->get(1, 0, $page);
			$count = $reportService->count(1, 0);
			$totalCount = $count ? $count : 0;
			$numofpage = ceil($count/$db_perpage);
			$pageurl = $basename . '&action=deal&type=second&';
			$pages=numofpage($count,$page,$numofpage,$pageurl);
			$select_second = 'selected';
			require_once PrintMode('report.deal');
			break;
		case 'rent':
			$reportdb = $reportService->get(1, 1, $page);
			$count = $reportService->count(1, 1);
			$totalCount = $count ? $count : 0;
			$numofpage = ceil($count/$db_perpage);
			$pageurl = $basename . '&action=deal&type=rent&';
			$pages=numofpage($count,$page,$numofpage,$pageurl);
			$select_rent = 'selected';
			require_once PrintMode('report.deal');
			break;
		default:
			$reportdb = $reportService->getByHandle(1, $page);
			$count = $reportService->countByHandle(1);
			$totalCount = $count ? $count : 0;
			$numofpage = ceil($count/$db_perpage);
			$pageurl = $basename . '&action=deal&';
			$pages=numofpage($count,$page,$numofpage,$pageurl);
			require_once PrintMode('report.deal');
			break;
	}	
} elseif ($action == 'done') {
	InitGP(array('selid', 'baseurl'));
	!$selid && adminmsg('operate_error');
	if (is_numeric($selid)) {
		$reportService->update($selid);
		adminmsg('operate_success', $baseurl);
	}
	$selids = array();
	foreach($selid as $value){
		is_numeric($value) && $selids[] =$value;
	}
	$selids && $reportService->updates($selids);
	adminmsg('operate_success', $baseurl);
} elseif ($action == 'del') {
	InitGP(array('selid', 'baseurl'));
	!$selid && adminmsg('operate_error');
	if (is_numeric($selid)) {
		$reportService->delete($selid);
		adminmsg('operate_success', $baseurl);
	}
	$selids = array();
	foreach($selid as $value){
		is_numeric($value) && $selids[] =$value;
	}
	$selids && $reportService->deletes($selids);
	adminmsg('operate_success', $baseurl);
}
?>